package idv.long.mcv.view
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	
	import idv.long.mcv.NotifyType;
	
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class MainAppMediator extends Mediator
	{
		public static const NAME:String = "MainAppMediator";
		
		/**
		 *	主要視覺化物件  其他Meditor 應在此建構式中個別建立
		 *  
		 * @param mediatorName
		 * @param viewComponent
		 * 
		 */		
		public function MainAppMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			
			this.root.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			this.root.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
/* 			var zooCanvas:ZooCanvas = new ZooCanvas();
			var zooCanvasMediator:GameCanvasMediator = new GameCanvasMediator(GameCanvasMediator.NAME, zooCanvas);
			facade.registerMediator(zooCanvasMediator);
			
			var storageUI:StoragePage = new StoragePage();						
			var storageMediator:StorageMediator = new StorageMediator(StorageMediator.NAME, storageUI);			
			facade.registerMediator(storageMediator); */

		}
		
/* 		override public function listNotificationInterests():Array
		{
			return [NotifyType.GAME_START];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
				case NotifyType.GAME_START:					
					break;
			}
		}
		 */
		public function get root():AngryZoo
		{
			return AngryZoo(viewComponent);
		}
		
		public function addChild(child:DisplayObject):void
		{
			this.viewComponent.addChild(child);
		}
		
		private function onEnterFrame(e:Event):void
		{
			facade.sendNotification(NotifyType.UPDATE);
			facade.sendNotification(NotifyType.RENDER);
		}
		
		private function onKeyDown(e:KeyboardEvent):void
		{
			facade.sendNotification(NotifyType.KEY_DOWN, e.keyCode);
		}
		
	}
}